package org.ztest.classloader;

import java.util.concurrent.TimeUnit;

public class ClassLoaderTest
{
    public void test() throws Exception
    {
        String clsName = "org.ztest.classloader.ClassLoaderTestBean";
        while (true)
        {
            // 此处为体现变化，循环创建类加载器，当clsName对应的类有改动(比如修改AA字段的值)时test.handle应该能反映出变化
            // 实际使用时应当在检测到类文件有变动时才重新创建类加载器
            MyClassLoader loader = new MyClassLoader(clsName);
            Class<?> cls = loader.loadClass(clsName);
            IClassLoaderTest test = (IClassLoaderTest) cls.newInstance();
            test.handle();
            TimeUnit.SECONDS.sleep(1);
        }
    }
}
